// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-05 21:32
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.SlideWindows;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MinimumDifference {
    /**
     * 计算给定学生分数的最小差值:
     * 获取n个最集中的元素
     */
    public int minimumDifference(int[] nums, int k) {
        // 1 暴力排序
        Arrays.sort(nums);
        int ans = nums[k - 1] - nums[0], n = nums.length;
        for (int i = k; i < n; i++) {
            ans = Math.min(ans, nums[i] - nums[i - k + 1]);
        }
        return ans;
    }
}
